package com.hongyi.demo.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.hongyi.common.log.annotation.Log;
import com.hongyi.common.web.controller.BaseController;
import com.hongyi.common.framework.domain.JsonResult;
import com.hongyi.common.log.enums.BusinessType;
import com.hongyi.demo.domain.dto.CeshiTreeDto;
import com.hongyi.demo.domain.vo.CeshiTreeVo;
import com.hongyi.demo.service.ICeshiTreeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.validation.annotation.Validated;
import com.hongyi.common.framework.validate.AddGroup;
import com.hongyi.common.framework.validate.EditGroup;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import com.hongyi.common.framework.utils.common.CollectionUtils;

import java.util.List;

/**
 * 树表展示Controller
 *
 * @author DingHao
 * @date 2025-01-18 20:10:49
 */
@ApiSort(value = 198)
@Api(tags = "树表展示控制器")
@RestController
@RequestMapping("/demo/tree")
public class CeshiTreeController extends BaseController {

    @Autowired
    ICeshiTreeService ceshiTreeService;

    /**
     * 查询树表展示分页列表
     * @param ceshiTreeDto 树表展示业务对象
     * @return 树表展示分页数据
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "查询树表展示分页列表")
    @ApiImplicitParam(name = "ceshiTree", value = "树表展示业务对象", paramType = "query", dataTypeClass = CeshiTreeDto.class)
    @SaCheckPermission("demo:tree:list")
    @GetMapping(value = "/list")
    public JsonResult<List<CeshiTreeVo>> list(CeshiTreeDto ceshiTreeDto) {
        List<CeshiTreeVo> list = ceshiTreeService.queryCeshiTreeVoList(ceshiTreeDto);
        return JsonResult.ok(list);
    }

    /**
     * 获取树表展示详细信息
     *
     * @param addressId 树表展示主键
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取树表展示详细信息")
    @ApiImplicitParam(name = "addressId", value = "树表展示主键", paramType = "path", dataTypeClass = Long.class, required = true)
    @SaCheckPermission("demo:tree:query")
    @GetMapping(value = "/{addressId}")
    public JsonResult<CeshiTreeVo> getInfo(@PathVariable("addressId") Long addressId) {
        return JsonResult.ok(ceshiTreeService.queryCeshiTreeVoById(addressId));
    }

    /**
     * 新增树表展示
     *
     *  @param ceshiTreeDto 树表展示业务对象
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增树表展示")
    @SaCheckPermission("demo:tree:add")
    @Log(title = "新增树表展示", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public JsonResult<Void> add(@Validated(AddGroup.class) @RequestBody CeshiTreeDto ceshiTreeDto) {
        return toResult(ceshiTreeService.addCeshiTree(ceshiTreeDto));
    }

    /**
     * 修改树表展示
     *
     * @param  ceshiTreeDto 树表展示业务对象
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "修改树表展示")
    @SaCheckPermission("demo:tree:edit")
    @Log(title = "修改树表展示", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/edit")
    public JsonResult<Void> edit(@Validated(EditGroup.class) @RequestBody CeshiTreeDto ceshiTreeDto) {
        return toResult(ceshiTreeService.editCeshiTree(ceshiTreeDto));
    }

    /**
     * 删除树表展示
     *
     * @param addressIds
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "删除树表展示")
    @ApiImplicitParam(name = "addressIds", value = "树表展示主键数组", paramType = "path", dataTypeClass = Long.class, allowMultiple = true, required = true)
    @SaCheckPermission("demo:tree:remove")
    @Log(title = "删除树表展示", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/{addressIds}")
    public JsonResult<Void> remove(@PathVariable Long[] addressIds) {
        return toResult(ceshiTreeService.removeCeshiTreeByIds(CollectionUtils.newArrayList(addressIds)));
    }

}
